package ch.zbw.pra.sysventory.presentation.panels;

import java.util.List;

import ch.zbw.pra.sysventory.application.controller.ProcessorController;
import ch.zbw.pra.sysventory.model.Processor;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

/**
 * Painted das ProcessorsArchivePanel
 * 
 * @author Ralph Koster
 */

public class ProcessorsArchivePanel extends VerticalLayout {

	private static final long serialVersionUID = 1L;
	private ProcessorController processorController;
	private Table processorsTable;
	
	public ProcessorsArchivePanel(){
		this.processorsTable = new Table ("Prozessoren im Netzwerk:");
		this.processorController = new ProcessorController();
		paint();
		loadProcessors();
		
	}

	private void paint() {
		this.setCaption("Prozessor");
		this.setStyleName("processorArchivePanel");
		processorsTable.setStyleName("table");
		processorsTable.addContainerProperty("Prozessor Name", String.class, null);
		processorsTable.addContainerProperty("Prozessor Familie", String.class, null);
		processorsTable.addContainerProperty("Anzahl Kerne", String.class, null);
		processorsTable.addContainerProperty("Takt", Integer.class, null);
		this.addComponent(processorsTable);	
		this.setComponentAlignment(processorsTable, Alignment.MIDDLE_CENTER);
	}

	private void loadProcessors() {
		processorsTable.removeAllItems();
		List<Processor> processors = processorController.loadProcessors();
		for(Processor processor : processors){
			int processorId = processor.getProcessorId();
			String processorName = processor.getNameProcessor();
			String processorFamily = processor.getFamilyProcessor();
			int processorCores = processor.getCoresProcessor();
			int processorClock = processor.getClockProcessor();
			processorsTable.addItem(new Object[]{
					processorName,processorFamily,processorCores,processorClock},processorId);
			}
	}

	public void updateProcessorArchivePanel() {
		loadProcessors();
	}
}
